<html>

<head>
    <meta charset="UTF-8">
    <link href="static/css/bootstrap.min.css" rel="stylesheet" type="text/css"/>
    <link href="static/css/components.css" rel="stylesheet" type="text/css"/>
    <link href="static/css/login.css" rel="stylesheet" type="text/css"/>
    <script src="static/js/jquery-1.11.1.min.js" type="text/javascript"></script>
</head>

    <body class="login" >
        <div class="content">
            <h3 class="form-title">获取otp信息</h3>
            <div class="form-group">
                <label class="control-label">手机号</label>
                <div>
                    <input class="form-control" type="text" placeholder="请输入11位手机号" name="telephone" id="telephone"/>
                </div>
            </div>
            <div class="form-actions" >
                <button  class="btn blue-steel" id="getOtp" type="submit">
                    获取otp短信
                </button>
            </div>
        </div>
    </body>
    <script>
        jQuery(document).ready(function () {

            // 绑定otp的click时间用于向后端发送获取手机验证码的请求
            $("#getOtp").on("click", function () {

                var telephone = $("#telephone").val();
                if (telephone == null || telephone === "") {
                    alert("手机号不能为空");
                    return false;
                }
                var g_userVO = {};
                $.ajax({
                    type: "POST",
                    contentType: "application/x-www-form-urlencoded",
                    url: "http://localhost:8090/user/getotp", // 部署时需要更改
                    data: {
                        "telephone":telephone,
                    },
                    // 前端跨域授信
                    xhrFields:{withCredentials:true},
                    success: function (data) {
                        if (data.status === "Success") {
                            g_userVO = data.data
                            alert("otp已经发送到您的手机上, 请注意查收，验证码为-> "+g_userVO.tempUsefulOtpCode);
                            window.location.href = "register.html?telephone=" + telephone;
                        } else {
                            alert("otp未发送到您的手机, 原因为" + data.data.errMsg);
                        }
                    },
                    error: function (data) {
                        alert("otp发送失败, 原因为" + data.responseText);
                    }
                });
                return false;
            })
        });
    </script>
</html>


